<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */

namespace App\Controller\Admin\Sys;

use App\Controller\AbstractController;
use App\Middleware\AuthMiddleware;
use App\Model\WebConfig;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\GetMapping;
use Hyperf\HttpServer\Annotation\Middlewares;
use Hyperf\HttpServer\Annotation\PutMapping;

#[Middlewares([AuthMiddleware::class])]
#[Controller]
class WebConfigController extends AbstractController
{
    #[GetMapping(path: '/sys/web/config')]
    public function config()
    {
        $webConfigs = WebConfig::query()
            ->select('id', 'name', 'logo', 'summary', 'record_num as recordNum', 'web_url as webUrl', 'author', 'author_info as authorInfo', 'author_avatar as authorAvatar', 'ali_pay as aliPay', 'weixin_pay as weixinPay', 'github', 'gitee', 'qq_number as qqNumber', 'qq_group as qqGroup', 'email', 'wechat', 'show_list as showList', 'login_type_list as loginTypeList', 'open_comment as openComment', 'open_admiration as openAdmiration', 'tourist_avatar as touristAvatar', 'bulletin', 'about_me as aboutMe', 'create_time as createTime', 'update_time as updateTime', 'open_lantern as openLantern')
            ->first();
        $extra = [
            'visitorCount' => 100,
            'blogViewsCount' => 1050,
        ];
        return success($webConfigs, $extra);
    }

    #[PutMapping(path: '/sys/web/update')]
    public function update()
    {
        WebConfig::query()->where('id', 1)->update([
                'about_me' => $this->request->input('aboutMe'),
                'author' => $this->request->input('author'),
                'author_avatar' => $this->request->input('authorAvatar'),
                'author_info' => $this->request->input('authorInfo'),
                'logo' => $this->request->input('logo'),
                'name' => $this->request->input('name'),
                'summary' => $this->request->input('summary'),
                'record_num' => $this->request->input('recordNum'),
                'web_url' => $this->request->input('webUrl'),
                'bulletin' => $this->request->input('bulletin'),
                'email' => $this->request->input('email'),
                'gitee' => $this->request->input('gitee'),
                'wechat' => $this->request->input('wechat'),
                'qq_group' => $this->request->input('github'),
                'github' => $this->request->input('qqGroup'),
                'qq_number' => $this->request->input('qqNumber'),
                'open_admiration' => $this->request->input('openAdmiration'),
                'open_comment' => $this->request->input('openComment'),
                'tourist_avatar' => $this->request->input('touristAvatar'),
            ]);

        return success();
    }
}
